from typing import Dict, Any, List
from .base_service_handler import BaseServiceHandler, ServiceHandlerFactory

class HTTPServiceHandler(BaseServiceHandler):
    """HTTP/HTTPS服务信息处理器"""
    
    def get_service_details(self, service_info: Dict[str, Any]) -> List[str]:
        """获取HTTP/HTTPS服务的详细信息"""
        details = []
        
        # 基本信息
        if service_info.get('product'):
            details.append(f"产品: {self._safe_str(service_info['product'])}")
        if service_info.get('version'):
            details.append(f"版本: {self._safe_str(service_info['version'])}")
            
        # HTTP特定信息
        if service_info.get('http_code'):
            details.append(f"HTTP状态码: {self._safe_str(service_info['http_code'])}")
        if service_info.get('http_title'):
            details.append(f"网页标题: {self._safe_str(service_info['http_title'])}")
        if service_info.get('http_server'):
            details.append(f"Web服务器: {self._safe_str(service_info['http_server'])}")
            
        # HTTP头信息
        if service_info.get('http_headers'):
            details.append("HTTP头信息:")
            for key, value in service_info['http_headers'].items():
                details.append(f"  - {self._safe_str(key)}: {self._safe_str(value)}")
                
        # SSL/TLS信息
        if service_info.get('ssl_info'):
            ssl_info = service_info['ssl_info']
            details.append("SSL/TLS信息:")
            ssl_fields = {
                'version': '版本',
                'cipher': '加密套件',
                'cert_subject': '证书主体',
                'cert_issuer': '证书颁发者',
                'cert_expire': '证书过期时间'
            }
            for field, label in ssl_fields.items():
                if ssl_info.get(field):
                    details.append(f"  {label}: {self._safe_str(ssl_info[field])}")
                    
        return details

# 注册HTTP服务处理器
ServiceHandlerFactory.register_handler('http', HTTPServiceHandler)
ServiceHandlerFactory.register_handler('https', HTTPServiceHandler) 